<?php
	class SEO
	{
		function cutString ($string, $separate)
		{
			if(strlen(trim($string))==0)
			{
				return false;
			}
			elseif(strpos($string, $separate)===false)
			{
				return $string;
			}
			else
			{
				$separateLen = strlen($separate);
				$separatePos = strpos($string, $separate);
				if($separatePos === false || $separateLen ==0)
				{
					$part[0] = $string;
					$part[1] = '';
				}
				else
				{
					$part[0] = substr($string, 0, $separatePos);
					$part[1] = substr($string, $separatePos + $separateLen);
				}
				return $part;
			}
		}
		
		function rewriteUrl()
		{
			$self = $_SERVER['PHP_SELF'];
			$stringParams = substr($self,strpos($self,'.php')+5);
			//echo $stringParams;
			$arrayParams = explode('/', $stringParams);
			//print_r($arrayParams);
			foreach ($arrayParams as $param)
			{
				//echo $param;
				//$aItem = $this->cutString($param, '-');
				$arrayParams1 = explode('-', $param);
				//print_r(($arrayParams1));
				//$_GET[$aItem[0]] = $aItem[1];
				$_GET[] = $arrayParams1;
			}
			//return $arrayParams;
		}
		
		function friendly_url($str) {
			$str = preg_replace("/(Ã |Ã¡|áº¡|áº£|Ã£|Ã¢|áº§|áº¥|áº­|áº©|áº«|Äƒ|áº±|áº¯|áº·|áº³|áºµ)/", 'a', $str);
			$str = preg_replace("/(Ã¨|Ã©|áº¹|áº»|áº½|Ãª|á»�|áº¿|á»‡|á»ƒ|á»…)/", 'e', $str);
			$str = preg_replace("/(Ã¬|Ã­|á»‹|á»‰|Ä©)/", 'i', $str);
			$str = preg_replace("/(Ã²|Ã³|á»�|á»�|Ãµ|Ã´|á»“|á»‘|á»™|á»•|á»—|Æ¡|á»�|á»›|á»£|á»Ÿ|á»¡)/", 'o', $str);
			$str = preg_replace("/(Ã¹|Ãº|á»¥|á»§|Å©|Æ°|á»«|á»©|á»±|á»­|á»¯)/", 'u', $str);
			$str = preg_replace("/(á»³|Ã½|á»µ|á»·|á»¹)/", 'y', $str);
			$str = preg_replace("/(Ä‘)/", 'd', $str);
			$str = preg_replace("/(Ã€|Ã�|áº |áº¢|Ãƒ|Ã‚|áº¦|áº¤|áº¬|áº¨|áºª|Ä‚|áº°|áº®|áº¶|áº²|áº´)/", 'A', $str);
			$str = preg_replace("/(Ãˆ|Ã‰|áº¸|áºº|áº¼|ÃŠ|á»€|áº¾|á»†|á»‚|á»„)/", 'E', $str);
			$str = preg_replace("/(ÃŒ|Ã�|á»Š|á»ˆ|Ä¨)/", 'I', $str);
			$str = preg_replace("/(Ã’|Ã“|á»Œ|á»Ž|Ã•|Ã”|á»’|á»�|á»˜|á»”|á»–|Æ |á»œ|á»š|á»¢|á»ž|á» )/", 'O', $str);
			$str = preg_replace("/(Ã™|Ãš|á»¤|á»¦|Å¨|Æ¯|á»ª|á»¨|á»°|á»¬|á»®)/", 'U', $str);
			$str = preg_replace("/(á»²|Ã�|á»´|á»¶|á»¸)/", 'Y', $str);
			$str = preg_replace("/(Ä�)/", 'D', $str);
			setlocale(LC_ALL, 'en_US.UTF8');
			$str = @iconv('UTF-8', 'ASCII//TRANSLIT', $str);
			//$str = str_replace(" ", "-", str_replace("&*#39;","",$str));
			//$url = preg_replace('~[^\\pL0-9_]+~u', '-', $str); 
			$str = strtolower($str); 
			$str = preg_replace('~[^-a-z0-9_]+~', '-', $str); 
			
			//$str = str_replace(" ", "-", str_replace("&*#39;","",$str));
			return $str;
		}	
		/* takes the input, scrubs bad characters */
		
		function generate_seo_link($input,$replace = '-',$remove_words = true,$words_array = array())
		{
			//make it lowercase, remove punctuation, remove multiple/leading/ending spaces
			$return = trim(ereg_replace(' +',' ',preg_replace('/[^a-zA-Z0-9\s]/','',strtolower($input))));
		
			//remove words, if not helpful to seo
			//i like my defaults list in remove_words(), so I wont pass that array
			if($remove_words) { $return = $this->remove_words($return,$replace,$words_array); }
		
			//convert the spaces to whatever the user wants
			//usually a dash or underscore..
			//...then return the value.
			return str_replace(' ',$replace,$return);
		}
		
		/* takes an input, scrubs unnecessary words */
		function remove_words($input,$replace,$words_array = array(),$unique_words = true)
		{
			//separate all words based on spaces
			$input_array = explode(' ',$input);
		
			//create the return array
			$return = array();
		
			//loops through words, remove bad words, keep good ones
			foreach($input_array as $word)
			{
				//if it's a word we should add...
				if(!in_array($word,$words_array) && ($unique_words ? !in_array($word,$return) : true))
				{
					$return[] = $word;
				}
			}
		
			//return good words separated by dashes
			return implode($replace,$return);
		}
		
		function dateDiff($date, $numDate)
		{
			$dateNow = time();
			$convertDate = new DateTime($date);
			$dateTime = $convertDate->getTimestamp();
			$dateDiff = $dateNow - $dateTime;
			$rs = $dateDiff/3600/24;
			if($rs <= $numDate)
			{
				return true;
			}
			else 
				return false;
			
		}

	}
?>


